package com.c.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.c.entity.*;
import com.c.mapper.CrmBannerMapper;
import com.c.mapper.PermissionMapper;
import com.c.mapper.RoleMapper;
import com.c.mapper.UserMapper;
import com.c.service.CrmBannerService;
import com.c.service.UserService;
import com.c.utils.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @author wangxiangli
 * @create 2022-12-25-12:30
 */
@Service
@Transactional
public class CrmBannerServiceImpl extends ServiceImpl<CrmBannerMapper, CrmBanner> implements CrmBannerService {


    /**
     * 轮播图分页查询
     * @param queryPageBean
     * @return
     */
    @Override
    public PageResult pageQuery(QueryPageBean queryPageBean) {
        IPage<CrmBanner> pageCrmBanner=new Page<>(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
        QueryWrapper<CrmBanner> wrapper=new QueryWrapper();
        String queryString = queryPageBean.getQueryString();
        //判断条件值是否为空，如果不为空拼接条件
        if (queryPageBean.getQueryString() != null && queryPageBean.getQueryString().length() > 0) {
            queryString = queryPageBean.getQueryString().trim();// 去除查询条件首尾空格
            wrapper.like("title",queryString);
            wrapper.orderByDesc("id");
        }
        IPage page1 = baseMapper.selectPage(pageCrmBanner, wrapper);
        return new PageResult(page1.getTotal(),page1.getRecords());

    }

    /**
     * 删除轮播图信息
     * @param id
     */
    @Override
    public void deleteById(String id) {
        //首先根据id拿到轮播图信息
        CrmBanner crmBanner = baseMapper.selectById(id);
        AliyunUtils.deleteFileFromAliyun(crmBanner.getImageUrl());
        baseMapper.deleteById(id);
    }
}
